#include "ScnsBmp280.c.h"

#if defined(SCNS_BMP280_ENABLE)&&SCNS_BMP280_ENABLE==1

#include "ScnsIic.h"
#include "ScnsMenu.h"
#include "ScnsSmctpExtOscilloscope.h"

ScnsStatus scnsBspBmp280Init(ScnsBmp280Enum bmpN)
{
    return SCNS_STATUS_OK;
}

ScnsStatus scnsBspBmp280PostInit(ScnsBmp280Enum bmpN)
{
    scnsMenuSetPage(1,"Bmp280",NULL);
    scnsMenuAddConstStruct(1,scnsBmp280Result[bmpN],temperature,,SCNS_TYPE_FLOAT);
    scnsMenuAddConstStruct(1,scnsBmp280Result[bmpN],pressure,,SCNS_TYPE_FLOAT);
    scnsMenuAddConstStruct(1,scnsBmp280Result[bmpN],altitude,,SCNS_TYPE_FLOAT);
    return SCNS_STATUS_OK;
}

static const uint8 device[SCNS_BMP280_MAX]={0XEC};

ScnsStatus scnsBspBmp280Write(ScnsBmp280Enum bmpN,const uint8*addr,uint8 addrLen,const uint8*data,uint8 dataLen)
{
    return scnsIicWrite(SCNS_IIC_SCL_B7_SDA_B6,device[bmpN],addr,addrLen,data,dataLen);
}

ScnsStatus scnsBspBmp280Read(ScnsBmp280Enum bmpN,const uint8*addr,uint8 addrLen,uint8*data,uint8 dataLen)
{
    return scnsIicRead(SCNS_IIC_SCL_B7_SDA_B6,device[bmpN],addr,addrLen,data,dataLen);
}

void scnsBspBmp280ResultUpdate(ScnsBmp280Enum bmpN)
{
    if(scnsMenuCanPageSend(1))
    {
        scnsSmctpExtOscilloscopeSend(SCNS_SMCTP_CHANNEL_VISUAL_SCOPE,SCNS_SMCTP_CHANNEL_VISUAL_SCOPE,
            scnsBmp280Result[bmpN].pressure,
            scnsBmp280Result[bmpN].temperature,
            scnsBmp280Result[bmpN].altitude,
        );
    }
    
}

#endif
